package yj.scms.userservice.action;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import yj.scms.userservice.service.UserService;
import yj.scms.userserviceapi.pojo.UserEntity;
import yj.scms.userserviceapi.pojo.utils.PojoPages;

import java.util.List;
import java.util.Map;

@Api(value="用户微服务api",tags={"用户微服务api"})
@RequestMapping("user")
@RestController
public class UseAction {


	@Autowired
	private UserService userService;

	//商品分页查询
	@ApiOperation(value = "查询商品品牌分页列表", notes = "查询商品品牌分页列表")
	@RequestMapping(value="/xml",method=RequestMethod.GET)
	public String xml(){
		List<UserEntity> userXmlBean = userService.UserXmlBean();
		List<Map<Object, Object>> userXmlHash = userService.UserXmlHash();
		
		StringBuffer buffer = new StringBuffer();
		buffer.append(userXmlBean.toString());
		buffer.append(userXmlHash.toString());
		
		return buffer.toString();
		
	}


	//商品分页查询
	@ApiOperation(value = "查询商品品牌分页列表", notes = "查询商品品牌分页列表")
	@ApiImplicitParam(name = "user", value = "classId(商品分类id条件传) goodName商品名(条件查询传传) current当前页(必传0开始) pageSize每页显示条数(必传大于0)", required = true, paramType = "body", dataType = "UserEntity")
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public Integer add(@RequestBody UserEntity user){
		Integer a = userService.addUser(user);
		return a;
	}
	
	@ResponseBody
	@RequestMapping(value="/get/{id}",method=RequestMethod.GET)
	public UserEntity get(@PathVariable("id") Long id){
		UserEntity user =	userService.queryUserById(id);
	   return user;
	}
	
	@ResponseBody
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public List<UserEntity> list(@RequestBody PojoPages<UserEntity> page){
		List<UserEntity> userList = userService.pagehelperUserList(page.getBean(),  page.getPage(), page.getLimit());
		return userList;
	}
	/**
	 * application/json 请求头传递
	 * @param page
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/pagelist",method=RequestMethod.POST)
	public List<UserEntity> listPage(@RequestBody PojoPages<UserEntity> page){
		List<UserEntity> userList = userService.pagehelperUserList(page.getBean(), page.getPage(), page.getLimit());
		return userList;
	}
	
	/**
	 * application/json 请求头传递
	 * @param page
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/putAdd",method=RequestMethod.PUT)
	public void listPut(@RequestBody PojoPages<UserEntity> page){
		Integer addUser = userService.addUser(page.getBean());
	}
	
	/**
	 * application/json 请求头传递
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteid/{id}",method=RequestMethod.DELETE)
	public void listDelete(@PathVariable("id") Long id){
		UserEntity user = userService.queryUserById(id);
		System.out.println(user.toString());
	}
}
